#include <cmath>
#include "../gameprog.h"

using namespace std;

/*-----------------------DOCUMENTATION-----------------------//
// FORCES.CPP                                                //
//    Contains force class and member functions              //
// Functions                                                 //
//    getForceMagnitude: returns magnitude of force vector   //
//    getForceDirection: returns direction of force vector   //
//    setForceMagnitude: sets force vector magnitude         //
//    setForceDirection: sets force vector direction         //
//    setForceXY: sets force vector by component             //
//    setForceMagDir: sets force vector by speed, direction  //
//-----------------------------------------------------------*/

class force
{
    public:
        force() : x(0), y(0), refresher(0) {};
        force(locvar nx, locvar ny) : x(nx), y(ny), refresher(0) {};
        force(locvar nx, locvar ny, bool nrefresh) : x(nx), y(ny), refresher(nrefresh) {};
        
        locvar x, y;    // components
        bool refresher;
        int id;
        
        locvar getForceMagnitude();
        locvar getForceDirection();
        
        void setForceMagnitude(locvar);
        void setForceDirection(locvar);
        void setForceXY(locvar, locvar);
        void setForceMagDir(locvar, locvar);
};

locvar force::getForceMagnitude() { return std::pow((std::pow(x,locvar(2)) + std::pow(y,locvar(2))),locvar(.5)); }
locvar force::getForceDirection() { return atan2(y,x); }
        
void force::setForceMagnitude(locvar nmagnitude)
{
    locvar multiplier = nmagnitude/getForceMagnitude();
    x *= multiplier;
    y *= multiplier;
}

void force::setForceDirection(locvar ndirection)
{
    locvar ux = cos(ndirection);
    locvar uy = sin(ndirection);
    x = ux * getForceMagnitude();
    y = uy * getForceMagnitude();
}

void force::setForceXY(locvar nfx, locvar nfy)
{
    x = nfx;
    y = nfy;
}

void force::setForceMagDir(locvar nmagnitude, locvar ndirection)
{
    locvar ux = cos(ndirection);
    locvar uy = sin(ndirection);
    x = ux * nmagnitude;
    y = uy * nmagnitude;
}
